package ${basePackage}.service.system.impl;

import ${basePackage}.dao.system.SystemJobMapper;
import ${basePackage}.dao.system.model.SystemJob;
import ${basePackage}.service.system.SystemJobService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class SystemJobServiceImpl implements SystemJobService {

    @Autowired
    private SystemJobMapper systemJobMapper;

    @Override
    public Integer create(SystemJob systemJob) {
        systemJobMapper.insert(systemJob);
        return systemJob.getId();
    }

    @Override
    public void deleteById(Integer id) {
        systemJobMapper.deleteById(id);
    }

    @Override
    public void delete(SystemJob systemJob) {
        UpdateWrapper<SystemJob> deleteWrapper = new UpdateWrapper<>(systemJob);
        systemJobMapper.delete(deleteWrapper);
    }

    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        systemJobMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateById(SystemJob systemJob) {
        systemJobMapper.updateById(systemJob);
    }

    @Override
    public void updateByIdInBatch(List<SystemJob> systemJobs) {
        if (CollectionUtils.isEmpty(systemJobs)) {
            return;
        }
        for (SystemJob systemJob: systemJobs) {
            this.updateById(systemJob);
        }
    }

    @Override
    public SystemJob findById(Integer id) {
        return systemJobMapper.selectById(id);
    }

    @Override
    public SystemJob findOne(SystemJob systemJob) {
        QueryWrapper<SystemJob> wrapper = new QueryWrapper<>(systemJob);
        return systemJobMapper.selectOne(wrapper);
    }

    @Override
    public List<SystemJob> findList(SystemJob systemJob) {
        QueryWrapper<SystemJob> wrapper = new QueryWrapper<>(systemJob);
        return systemJobMapper.selectList(wrapper);
    }

    @Override
    public long count(SystemJob systemJob) {
        QueryWrapper<SystemJob> wrapper = new QueryWrapper<>(systemJob);
        return systemJobMapper.selectCount(wrapper);
    }
}
